package com.xbongbong.saas.enums;

import com.alibaba.fastjson.JSONObject;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 签到设置 距离和可见范围枚举
 *
 * @author youli.chen
 * @version v1.0
 * @date 2019/1/11 16:12
 * @since v1.0
 */
public class SignInSetEnum {
    /**
     * 微调类型枚举
     */
    public @Getter
    enum AdjustType {
        // 微调100米
        ADJUST_TYPE_100(100, "100米", 1),
        // 微调200米
        ADJUST_TYPE_200(200, "200米", 2),
        // 微调500米
        ADJUST_TYPE_500(500, "500米", 3),
        // 微调1000米
        ADJUST_TYPE_1000(1000, "1000米", 4),
        // 非法类型
        UNKNOWN(-1, "未知", 404);

        private Integer adjustDistance;
        private String name;
        private int code;

        AdjustType(Integer adjustDistance, String name, int code) {
            this.adjustDistance = adjustDistance;
            this.name = name;
            this.code = code;
        }

        public static AdjustType getAdjustByCode(Integer code) {
            if (code == null) {
                return UNKNOWN;
            }
            for (AdjustType type : AdjustType.values()) {
                if (Objects.equals(type.getCode(), code)) {
                    return type;
                }
            }
            return UNKNOWN;
        }
        /**
         * 通过code获取微调距离
         * @param code
         * @return java.lang.String
         * @author zcp
         * @date 2019/6/28 20:29
         * @since v1.0
         * @version v1.0
         */
        public static String getAdjustNameByCode(Integer code) {
            if (code == null) {
                return "";
            }
            for (AdjustType cache : AdjustType.values()) {
                if (Objects.equals(cache.getCode(), code)) {
                    return cache.name;
                }
            }
            return "";
        }

        /**
         * 获取微调类型列表
         *
         * @author GuoJun.HU
         * @date 2019/1/22 16:47
         * @since v1.0
         */
        public static List<JSONObject> getAdjustTypeList() {
            List<JSONObject> typeList = new ArrayList<>();
            for (AdjustType type : AdjustType.values()) {
                if (type == UNKNOWN) {
                    continue;
                }
                JSONObject itemObj = new JSONObject();
                itemObj.put("key", type.getCode());
                itemObj.put("value", type.getName());
                typeList.add(itemObj);
            }
            return typeList;
        }
    }

    /**
     * 可见范围枚举类型
     */
    public @Getter
    enum VisibleDistance {
        // 可见范围500米
        VISIBLE_DISTANCE_500(500, "500米", 1),
        // 可见范围1000米
        VISIBLE_DISTANCE_1000(1000, "1000米", 2),
        // 可见范围1500米
        VISIBLE_DISTANCE_1500(1500, "1500米", 3),
        // 可见范围3000米
        VISIBLE_DISTANCE_3000(3000, "3000米", 4),
        // 可见范围不限制
        VISIBLE_DISTANCE_UNLIMITED(-1, "不限制", 5),
        // 非法类型
        UNKNOWN(404, "未知", 404);

        private Integer distance;
        private String name;
        private int code;

        VisibleDistance(Integer distance, String name, int code) {
            this.distance = distance;
            this.name = name;
            this.code = code;
        }

        public static VisibleDistance getVisibleDistanceByCode(Integer code) {
            if (code == null) {
                return UNKNOWN;
            }
            for (VisibleDistance distance : VisibleDistance.values()) {
                if (Objects.equals(distance.getCode(), code)) {
                    return distance;
                }
            }
            return UNKNOWN;
        }
        /**
         * 通过code获取可见范围
         * @param code
         * @return java.lang.String
         * @author zcp
         * @date 2019/6/28 20:34
         * @since v1.0
         * @version v1.0
         */
        public static String getVisibleDistanceNameByCode(Integer code) {
            if (code == null) {
                return "";
            }
            for (VisibleDistance distance : VisibleDistance.values()) {
                if (Objects.equals(distance.getCode(), code)) {
                    return distance.name;
                }
            }
            return "";
        }

        /**
         * 获取可见范围列表
         *
         * @author GuoJun.HU
         * @date 2019/1/22 16:47
         * @since v1.0
         */
        public static List<JSONObject> getVisibleDistanceList() {
            List<JSONObject> distanceList = new ArrayList<>();
            for (VisibleDistance distance : VisibleDistance.values()) {
                if (distance == UNKNOWN) {
                    continue;
                }
                JSONObject itemObj = new JSONObject();
                itemObj.put("key", distance.getCode());
                itemObj.put("value", distance.getName());
                distanceList.add(itemObj);
            }
            return distanceList;
        }
    }
}
